import React, { useEffect, useState } from "react"
import { Image, PullToRefresh, Toast } from 'antd-mobile'
import { httpJson } from "../../../../../services/http"
import ProductItem from "../product-item"

const OnSaleList: React.FC = () => {
    const [list, setList] = useState<any>([])
    const [loading, setLoading] = useState<boolean>(false)
    const getOnSaleGoodsList = async () => {
        setLoading(true)
        httpJson('POST','/api/goods/getGoodsInfoList', {status: '0'})
        .then((res: any)=>{
          console.log(res.data.data)
          setList(res.data.data)
          setLoading(false)
        })
        .catch(err => {
          console.log(err)
          setLoading(false)
        })
    }
    useEffect(() => {
        getOnSaleGoodsList()
    }, [])
    return (
        <PullToRefresh
            onRefresh={getOnSaleGoodsList}
        >
            {list && list.length > 0 &&
                list.map((item: any) => {
                    return <ProductItem currentKey="0" props={item} refresh={getOnSaleGoodsList} />
                })
            }
            {
                !loading && !list.length && (
                    <p style={{ maxHeight: 800, minHeight: 600, textAlign: 'center', fontSize: 20, color: '#999', lineHeight: 20 }}>暂无数据...</p>
                )
            }
        </PullToRefresh>
    )
}

export default OnSaleList